package com.fortune.rainshine.system.controller;

import com.fortune.rainshine.common.BaseController;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpServletRequest;
import java.util.Set;

@Controller()
@RequestMapping("/home")
public class HomeController extends BaseController{

    /**
     * 控制台
     */
    @RequestMapping("/console")
    public String console(Model model) {
    	// 获取用户权限
    	Set<String> authorities = getLoginUserAuthorities();
    	// 获取登录用户的按钮展示情况
    	model.addAttribute("purchase", authorities.contains("purchase:view"));
    	model.addAttribute("stock", authorities.contains("stock:view"));
    	model.addAttribute("orderSell", authorities.contains("orderSell:view"));
    	model.addAttribute("orderBuy", authorities.contains("orderBuy:view"));
    	
    	model.addAttribute("customer", authorities.contains("customer:view"));
    	model.addAttribute("customerCard", authorities.contains("customerCard:view"));
    	model.addAttribute("payCard", authorities.contains("payCard:view"));
    	model.addAttribute("productSale", authorities.contains("productSale:view"));
    	
        return "home/console.html";
    }

    /**
     * 消息弹窗
     */
    @RequestMapping("/message")
    public String message() {
        return "tpl/message.html";
    }

    /**
     * 修改密码弹窗
     */
    @RequestMapping("/password")
    public String password() {
        return "tpl/password.html";
    }

    /**
     * 主题设置弹窗
     */
    @RequestMapping("/theme")
    public String theme() {
        return "tpl/theme.html";
    }

    /**
     * 设置主题
     */
    @RequestMapping("/setTheme")
    public String setTheme(String themeName, HttpServletRequest request) {
        if (null == themeName) {
            request.getSession().removeAttribute("theme");
        } else {
            request.getSession().setAttribute("theme", themeName);
        }
        return "redirect:/";
    }
}
